Component({
  data: {
    text: "",
    show: false,
    comName: "calendar-demo-04",
    minDate: new Date(2010, 0, 1).getTime(),
    maxDate: new Date(2010, 0, 31).getTime(),
  },
  lifetimes: {
    created() {
      console.log(`${this.data.comName} created`);
    },
    ready() {
      console.log(`${this.data.comName} ready`);
    },
    attached() {
      console.log(`${this.data.comName} attached`);
    },
    moved() {
      console.log(`${this.data.comName} moved`);
    },
  },
  pageLifetimes: {
    hide() {
      console.log(`${this.data.comName} hide`);
    },
    resize() {
      console.log(`${this.data.comName} resize`);
    },
    show() {
      console.log(`${this.data.comName} show`);
    },
  },
  methods: {
    onDisplay() {
      this.setData({ show: true });
    },
    onClose() {
      this.setData({ show: false });
    },
    formatDate(date: any) {
      const d = new Date(date);
      return `${d.getMonth() + 1}/${d.getDate()}`;
    },
    onConfirm(event: WechatMiniprogram.CustomEvent) {
      const [start, end] = event.detail as string[];
      this.setData({
        show: false,
        text: `${this.formatDate(start)} - ${this.formatDate(end)}`,
      });
    },
  },
});
